/*
 * cmdinterpreter.h
 *
 *  Created on: 2021年12月10日
 *      Author: t1019
 */

#ifndef CMDINTERPRETER_H_
#define CMDINTERPRETER_H_

namespace bt_cmdinterpreter {

typedef struct _CmdNodeType
{
	unsigned char event;
	struct _CmdNodeType* node;
	struct _CmdNodeType* next;
	void (*func)(char*);
	struct _CmdNodeType* parent;
}s_CmdNode;

typedef struct
{
	const unsigned char event;
	const char* group;
}s_CmdGroup;

class CmdInterpreter {
public:
	CmdInterpreter(const s_CmdNode* p);
	void handler(char e);
	void setGroups(const s_CmdGroup* gr);
	void setQuit(const char ch);
	void setBack(const char ch);
	virtual ~CmdInterpreter();
private:
	bool _is_ingroup(char e,unsigned char event);
	bool _append_event(char e);
	void _clear_buffer();
	void _back_root();
	const s_CmdNode *root, *current;
	const s_CmdGroup* group;
	const int max_length = 10;
	char buffer[10+1];
	char quit,back;
};

} /* namespace bt_cmdinterpreter */

#endif /* CMDINTERPRETER_H_ */
